package com.aos.erp.schools.rest.coach;

import com.aos.erp.common.bean.IPageBean;
import com.aos.erp.common.bean.ResultEntity;
import com.aos.erp.common.exception.BizException;
import com.aos.erp.schools.model.coach.*;
import com.aos.erp.schools.service.coach.CoachService;
import com.aos.erp.schools.util.UserUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController("CoachController")
@RequestMapping("/api/coach")
@Api(value="教练接口",tags={"教练管理"})
public class CoachController {

    @Resource
    private CoachService coachService;

    @GetMapping("/list")
    @ApiOperation(value = "分页查询")
    public ResultEntity<IPageBean<ShowCoachVo>> queryPageBean(QueryCoachRo queryCoachRo) throws Exception {
        return ResultEntity.success(coachService.queryByPage(queryCoachRo));
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增教练")
    public ResultEntity addCoach(@Validated AddCoachRo addCoachRo, String currentUserId) throws Exception {
        ///////////////////////////////////
        //TODO 暂时写死教练编号
        addCoachRo.setCurrentUserId(currentUserId);
        addCoachRo.setCoachNumber("68629315");
        ////////////////////////////////////
        coachService.addBean(addCoachRo);
        return ResultEntity.success();
    }


    @PostMapping("/delete")
    @ApiOperation(value = "删除教练")
    @ApiImplicitParam(name = "id",value = "教练ID",required = true,dataType ="long",paramType ="query" )
    public ResultEntity delCoach( long id) throws BizException {
        coachService.delCoach(id);
        return ResultEntity.success();
    }


    @PostMapping("/info")
    @ApiOperation(value = "教练信息")
    @ApiImplicitParam(name = "id",value = "教练ID",required = true,dataType ="long",paramType ="query" )
    public ResultEntity<CoachInfoVo> coachInfo( long id) throws BizException {
        CoachInfoVo coachInfoVo=coachService.coachInfo(id);
        return ResultEntity.success(coachInfoVo);
    }


    @PostMapping("/update")
    @ApiOperation(value = "修改教练")
    public ResultEntity updateCoach(@Validated UpdateCoachRo UpdateCoachRo) throws BizException {
        ///////////////////////////////////
        ////////////////////////////////////
        int i=coachService.updateCoach(UpdateCoachRo);
        return ResultEntity.success();
    }

  /*  @PostMapping("/aaa")
    @ApiOperation(value = "根据当前用户获取总校信息")
    public ResultEntity aaa(Integer pageIndex,Integer pageSize,String schoolId,String name) throws Exception {
        IPage<Coach> gatherSchool=coachService.queryCoachBySchoolId(pageIndex,pageSize,schoolId,name);
        return ResultEntity.success(gatherSchool);
    }*/

}